using System;
using UnityEngine;

namespace World
{
    public class WorldInfo : MonoBehaviour
    {
        public static WorldInfo Instance { get; private set; }
        
        public float WorldRadius => worldRadius;

        public Transform Player => player;

        [SerializeField] private float worldRadius;
        
        [SerializeField] private Transform player;


        private void Awake()
        {
            Instance = this;
        }

        private void Update()
        {
            player.transform.position = Vector3.ClampMagnitude(player.transform.position, worldRadius);
        }

        public bool IsOutOfBound(Vector2 position)
        {
            return position.sqrMagnitude > (worldRadius * worldRadius);
        }

        private void OnDrawGizmosSelected()
        {
            Gizmos.color = Color.cyan;
            Gizmos.DrawWireSphere(Vector3.zero, worldRadius);
        }
    }
}